package liudan.archetype.action;

import liudan.archetype.annotation.Controller;
import liudan.archetype.annotation.RequestMapping;
import liudan.archetype.enums.RequestMethod;

import javax.servlet.http.HttpServletRequest;

/**
 * Description:
 * Email: liudan@ucfgroup.com
 * Title
 * Copyright: Copyright (c) 2017
 * User: liudan
 * Created on 2017/3/6 15:23
 */
@Controller
@RequestMapping("/api/user")
public class UserAction {


    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login(HttpServletRequest request) {
        String username = request.getParameter("username");
        if ("admin".equals(username)) {
            request.setAttribute("message", "<h1>登录成功，欢迎您，" + username + "</h1>");
            return "/page/success.jsp";
        } else {
            request.setAttribute("message", "登录失败");
        }
        return "/page/faile.jsp";
    }

    @RequestMapping(value = "/register", method = RequestMethod.GET)
    public String register(HttpServletRequest request) {
        String username = request.getParameter("username");
        if (username != null) {
            request.setAttribute("message", "注册成功");
            return "/page/success.jsp";
        } else {
            request.setAttribute("message", "注册失败");
            return "/page/faile.jsp";
        }
    }
}
